import type { Directive, App } from 'vue'
import useGlobalStore from '@/store/modules/global'

const authDirective: Directive = {
  mounted(el, binding) {
    const globalStore = useGlobalStore()
    if (globalStore.permissions.length === 0 || (globalStore.permissions && !globalStore.permissions.includes(binding.value))) {
      el.parentNode && el.parentNode.removeChild(el)
    }
  }
}

export function setupAuthDirective(app: App) {
  app.directive('auth', authDirective)
}

export default authDirective
